package org.csu.mypetstore.web.servlets;

import org.csu.mypetstore.domain.Account;
import org.csu.mypetstore.domain.Cart;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * Created by songtie on 2015/4/27.
 */
public class ViewCartServlet extends HttpServlet {

    private static final String VIEW_CART = "/WEB-INF/jsp/cart/Cart.jsp";

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        Account account = (Account)request.getSession().getAttribute("account");
//        Cart cart = (Cart)session.getAttribute("cart");
//
//        if (cart == null) {
//            cart = new Cart();
//            session.setAttribute("cart", cart);
//        }
//
//
//        request.getRequestDispatcher(VIEW_CART).forward(request, response);
        if (account==null){
            request.getSession().setAttribute("login_msg","您尚未登录，请登录后再进行操作！");
            request.getRequestDispatcher("/WEB-INF/jsp/account/SignonForm.jsp").forward(request,response);
        }
        response.sendRedirect(request.getContextPath()+"/longcart");
    }
}
